<?php
class CommonController extends Controller {
	//设备
	function DeviceAction()
	{
		$this->view("common.agency.select","item");
	}
	
	function DevicedataAction(){
		$this->json->toJson(array("total"=>CommonModel::getInstance()->getDeviceCount(),"data"=>CommonModel::getInstance()->getDeviceList()));
	}
	
	// 机构
	function AgencyAction()
	{
		$p['agency'] = $this->user["agency_id"];
		$this->json->toJson(CommonModel::getInstance()->getAgencyList($p));
	}
	
	// 机构
	function AgencyOneAction()
	{
		$p['agency'] = $this->user["agency_id"];
		$this->json->toJson(CommonModel::getInstance()->getAgencyComboxOne($p));
	}
	
	// 机构
	function AgencyTwoAction()
	{
		$p['agency'] = $this->user["agency_id"];
		$p['business'] = G("business","0");
		$this->json->toJson(CommonModel::getInstance()->getAgencyComboxTwo($p));
	}
	
	// 区域
	function AreaAction()
	{
		$this->json->toJson(CommonModel::getInstance()->getAreaList());
	}
	
	// 部门
	function PositionAction()
	{
		$p['agency'] = P('agency',0);
		$this->json->toJson(array("total"=>"100","data"=>CommonModel::getInstance()->getPositionList($p)));
	}
	
	// 员工
	function StaffAction()
	{
		$this->view("common.staff.select","item");
	}
	
	function StaffdataAction()
	{
		$agency = CommonModel::getInstance()->getAgencyAllList();
		$agency_id = ArrayTool::ArrayToIDs($agency,$this->user["agency_id"]);
		$this->json->toJson(array("total"=>CommonModel::getInstance()->getStaffCount($agency_id),"data"=>CommonModel::getInstance()->getStaff($agency_id)));
	}
	
	// 顾客
	function CustomerAction()
	{
		$this->view("common.customer.select","item");
	}
	
	function CustomerdataAction()
	{
		$p["name"] = trim(P("key",""));
		$area = trim(P("area","1"));
		
		$areaList = CommonModel::getInstance()->getAreaList();
		$area_id = ArrayTool::ArrayToIDs($areaList,$area);
		$p["area"] = $area_id;

		$this->json->toJson(array("total"=>CommonModel::getInstance()->getCustomerCount($p),"data"=>CommonModel::getInstance()->getCustomer($p)));
	}
	
	// 顾客详情
	function CustomerInfoAction(){
		$p["id"] = G("id","0");
		$this->data['customerInfo'] = CustomerModel::getInstance()->getCustomerInfo($p);
		$this->view("common.customer.view","item");
	}
	
	// 工单详情
	function BusinessInfoAction(){
		$p["id"] = G("id","0");
		$this->data['businessInfo'] = BusinessModel::getInstance()->getBusinessInfo($p);
		$this->view("common.business.view","item");
	}
	
	// 工单详情
	function BusinessInfo2Action(){
		$p["id"] = G("id","0");
		$this->data['businessInfo'] = BusinessModel::getInstance()->getBusinessInfo2($p);
		$this->view("common.business.view","item");
	}
	
	// 未处理消息
	function BLogAlertAction(){
		$p["cid"] = $this->user["cid"];
		$count = CommonModel::getInstance()->BLogCount($p);
		$data  = CommonModel::getInstance()->BLogList3($p);
		$this->json->count($count)->data($data)->out();
	}
	
	// 未处理信息列表
	function BLogListAction(){
		return $this->sql("select content,created from crm_business_log where receive_flg=0 and msg_flg=1 and accept_flg=0 and receive=[receive] order by id desc ",$p)->s();
	}
	
	// 取得类型下的品牌
	function DeviceBrandAction(){
		header("Content-Type: text/html; charset=utf-8");
		$p['types']=urldecode(G('types',''));
		$rs = DeviceModel::getInstance()->DeviceBrand($p);
		$this->json->toJson($rs);
	}
	
	// 取得类型下的品牌
	function DevicePatternAction(){
		header("Content-Type: text/html; charset=utf-8");
		$p['types']=urldecode(G('types',''));
		$p['brand']=urldecode(G('brand',''));
		$rs = DeviceModel::getInstance()->DevicePattern($p);
		$this->json->toJson($rs);
	}
}